package com.ihr360.binlog.service.convertor;

import com.google.common.collect.Lists;
import com.ihr360.binlog.dto.BinLogReceivedEvent;
import com.ihr360.commons.entity.event.BinLogReceivedEventEntity;
import com.ihr360.commons.lang.CollectionUtils;
import com.ihr360.commons.model.IConvertor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class BinLogReceivedEventConvertor implements IConvertor<BinLogReceivedEventEntity, BinLogReceivedEvent> {
    @Override
    public BinLogReceivedEvent convertEntityToDto(BinLogReceivedEventEntity entity) {
        return null;
    }

    @Override
    public BinLogReceivedEventEntity convertDtoToEntity(BinLogReceivedEvent dto) {
        BinLogReceivedEventEntity entity = new BinLogReceivedEventEntity();
        BeanUtils.copyProperties(dto,entity);
        return entity;
    }

    public List<BinLogReceivedEventEntity> convertDtosToEntities(List<BinLogReceivedEvent> dtos) {
        if (CollectionUtils.isEmpty(dtos)) {
            return Lists.newArrayList();
        }
        List<BinLogReceivedEventEntity> entities = Lists.newArrayListWithCapacity(dtos.size());
        dtos.forEach(dto -> {
            entities.add(convertDtoToEntity(dto));
        });
        return entities;
    }

}
